Use the LungCapData to answer the following questions. (Hint: Using dplyr, especially group_by() and summarize() can help you answer the following questions relatively efficiently.)
Install Libraries
#install.packages("dplyr")library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
Error in eval(predvars, data, env): object 'LungCapData' not found
c. Compare the mean lung capacities for smokers and non-smokers. Does it make sense? In comparing the means, the lung capacity for smokers is higher than for nonsmokers.
#Mean Lung capacities of smokersLungCapData %>%filter(Smoke =='yes') %>%pull(LungCap) %>%mean()
Error in filter(., Smoke == "yes"): object 'LungCapData' not found
#Mean Lung capacities of non-smokersLungCapData %>%filter(Smoke =='no') %>%pull(LungCap) %>%mean()
Error in filter(., Smoke == "no"): object 'LungCapData' not found
d. Examine the relationship between Smoking and Lung Capacity within age groups: “less than or equal to 13”, “14 to 15”, “16 to 17”, and “greater than or equal to 18”.
#new var for Age GroupsLungCapData$Age_Cat <-cut(LungCapData$Age,breaks =c(0,13,15,17,25),labels =c('less than or equal to 13','14 to 15','16 to 17','greater than or equal to 18'))
Error in cut(LungCapData$Age, breaks = c(0, 13, 15, 17, 25), labels = c("less than or equal to 13", : object 'LungCapData' not found
Error in ggplot(LungCapData, aes(x = Smoke, y = LungCap)): object 'LungCapData' not found
e. Compare the lung capacities for smokers and non-smokers within each age group. Is your answer different from the one in part c. What could possibly be going on here? We see an intervening relationship with age. Where most young children either don’t smoke ar all and have smaller lung capacities because of their size.